package com.testing.class6.vPo;

import com.testing.web.WebKeywords;
import org.openqa.selenium.WebDriver;

/**
 * @Classname ShopAdminTest
 * @Description 类型说明
 * @Date 2022/10/12 20:06
 * @Created by 特斯汀Roy
 */
public class ShopAdminPage extends WebKeywords {
    //属性
    //url
    String url="http://www.testingedu.com.cn:8000/index.php/Admin";
    //元素
//    WebElement userinput=findElement("//input[@name='username']");

    public ShopAdminPage(){
        open("chrome");
        visitWeb(url);
    }

    public ShopAdminPage(WebDriver driver){
        setDriver(driver);
        visitWeb(url);
    }

    //方法
    public void login(){
        input("//input[@name='username']", "admin");
//        userinput.sendKeys("admin");
        input("//input[@name='password']", "123456");
        input("//input[@name='vertify']", "1");
        click("//input[@value='登录']");
    }
    
    public void addGoods(){
        //切换Iframe
        switchIframe("workspace");
        //添加商品
        click("//span[text()='添加商品']");
        saveDateParam("随机商品","VIP14测试商品","ddHHmmss");
        input("//input[@name='goods_name']","{随机商品}");
        click("//select[@id='cat_id']");
        selectByText("#cat_id", "服饰");
        halt("0.5");
        selectByText("#cat_id_2", "男装");
        halt("0.5");
        selectByText("#cat_id_3", "羽绒服");
        input("//input[@name='shop_price']","300");
        input("//input[@name='market_price']","500");
        //文件上传
        click("//input[contains(@title,'点击前方预览图可查看大图')]");
        switchIframe("//iframe[contains(@id,'layui')]");
        input("//div[text()='点击选择文件']/following-sibling::div[@id]/input","E:\\QSwork\\素材\\图片素材\\airtestLogo.jpg");
        halt("1");
        click("//div[text()='确定使用']");
        switchIframe("workspace");
        //选择是 包邮
        click("//label[text()='是' and @id]");
        click("//a[text()='确认提交']");
        //断言标准是第一个元素的商品名称是VIP13测试商品
        assertElementTextContains("//div[@id='flexigrid']//tr[1]/td[4]", "{随机商品}");
        assertDbExists("select * from tp_goods where goods_name = '{随机商品}'");
        halt("3");
    }

}
